/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * ArmItemRegionalityEqualsPredicate.java
 * business
 * 2013-2-25上午9:18:36
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.report;

import org.jackysoft.entity.ArmItem;
import org.jackysoft.entity.ProductType;
import org.jackysoft.util.StringUtils;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


@Component(ReportConstant.ArmItemRegionEqualPredicate)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ArmItemRegionEqualsPredicate extends ArmItemEqualPredicate{

    private ArmItem source;
    private ProductType sourceType;
	
    public ArmItemRegionEqualsPredicate(){}
    
	public ArmItemRegionEqualsPredicate(ArmItem item ,ProductType type) {
		init(item,type);
	}
	public void init(ArmItem item ,ProductType type){
		this.source     = item;
		this.sourceType = type;
	}
	@Override
	public boolean evaluate(Object arg0) {
		if(source==null) return false;
		ArmItem i = (ArmItem) arg0;
		if(i==null || i.getHost()==null)return false;
		String code1 = StringUtils.lowerCase(StringUtils.trim(i.getHost().getCode()));
		String code2 = StringUtils.lowerCase(StringUtils.trim(this.source.getHost().getCode()));
		return code1.equals(code2) && this.sourceType==i.getItemType();
	}
}
